﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;


namespace XjjXmm.Infrastructure.Repository;

public interface IRepositoryBase<T> where T : class, new()
{

    /// <summary>
    /// 返回是否成功
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> Add(T entity);

    /// <summary>
    /// 返回是否成功
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> Add(List<T> entity);

    /// <summary>
    /// 返回主键
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<long> AddReturnIdentity(T entity);

    /// <summary>
    /// 返回主键
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<long> AddReturnSnowflakeId(T entity);

    /// <summary>
    /// 批量返回主键
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<List<long>> AddReturnSnowflakeId(List<T> entity);

    /// <summary>
    /// 更新实体
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> Update(T entity);

    /// <summary>
    /// 根据主键删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    Task<bool> Delete(dynamic id);

    /// <summary>
    /// 条件删除
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>

    Task<bool> Delete(Expression<Func<T, bool>> whereExpression);

    /// <summary>
    /// 软删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    Task<bool> SoftDelete(dynamic id);

    /// <summary>
    /// 批量软删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    Task<bool> SoftDelete(dynamic[] id);

    /// <summary>
    /// 条件软删除
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>
    //Task<bool> SoftDelete(Expression<Func<T, bool>> whereExpression);

    Task<T> Find(dynamic id);

    Task<T> First(Expression<Func<T, bool>> whereExpression);

    Task<List<T>> GetAll();

    Task<List<T>> Get(Expression<Func<T, bool>> whereExpression);

    IRepositoryQuery<T> Queryable();
    
    string GetTableName(object fieldValue);
}
